package cn.tedu.crm.dict.controller;

import cn.tedu.crm.base.pojo.PageObject;
import cn.tedu.crm.base.response.JsonResult;
import cn.tedu.crm.dict.pojo.dto.DictQuery;
import cn.tedu.crm.dict.pojo.dto.DictSaveParam;
import cn.tedu.crm.dict.pojo.vo.DictVO;
import cn.tedu.crm.dict.service.DictService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/sys/dict")
public class DictController {

    @Autowired
    DictService dictService;

    @GetMapping("/select")
    public JsonResult selectDict( DictQuery dictQuery){
        //log.debug("查询字典：{}", dictQuery);
        //List<DictVO> list = dictService.selectDict(dictQuery);
        PageObject<DictVO> pageObject = PageObject.page(dictQuery.getPageNum(),dictQuery.getPageSize(),
                ()->dictService.selectDict(dictQuery));
        return JsonResult.ok(pageObject);
    }

    @PostMapping("/save")
    public JsonResult saveDict(@RequestBody DictSaveParam dictSaveParam){
        //log.debug("保存字典：{}", dictSaveParam);
        dictService.saveDict(dictSaveParam);
        return JsonResult.ok();
    }


    @PostMapping("/delete/{id}")
    public JsonResult deleteDict(@PathVariable Long id){
        //log.debug("删除字典：{}", id);
        dictService.deleteDict(id);
        return JsonResult.ok();
    }


}





